package app.controllers;

import app.models.enums.TipoConsulta;
import app.services.ConsultaService;
import app.services.PacienteService;
import app.util.DateUtils;
import br.com.caelum.vraptor.Get;
import br.com.caelum.vraptor.Resource;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.Validator;

/**
 * @author Douglas Fernandes
 * @since 25/11/2013
 */

@Resource
public class IndexController extends Controller{

	private final Result result;
	private final PacienteService pacienteService;
	private final ConsultaService consultaService;

	public IndexController(Result result, PacienteService pacienteService, 
			ConsultaService consultaService, Validator validator) {
		
		this.result = result;
		this.pacienteService = pacienteService;
		this.consultaService = consultaService;
	}

	@Get("/")
	public void index() {
		result.include("today", DateUtils.getDiaAtual());
		result.include("month", DateUtils.getMesAtual());
		result.include("year", DateUtils.getAnoAtual());

		result.include("qntConsultasHoje", consultaService.amountConsultasToday());
		result.include("qntConsultasSemana", consultaService.amountConsultasWeek());
		result.include("qntConsultasMes", consultaService.amountConsultasMonth());
		
		result.include("pcntConsultasParticularHoje", consultaService.amountPcntConsultasToday(TipoConsulta.PARTICULAR));
		result.include("pcntConsultasParticularSemana", consultaService.amountPcntConsultasWeek(TipoConsulta.PARTICULAR));
		result.include("pcntConsultasParticularMes", consultaService.amountPcntConsultasMonth(TipoConsulta.PARTICULAR));
		
		result.include("pcntConsultasConvenioHoje", consultaService.amountPcntConsultasToday(TipoConsulta.CONVENIO));
		result.include("pcntConsultasConvenioSemana", consultaService.amountPcntConsultasWeek(TipoConsulta.CONVENIO));
		result.include("pcntConsultasConvenioMes", consultaService.amountPcntConsultasMonth(TipoConsulta.CONVENIO));

		result.include("ultimasConsultas", consultaService.findLastConsultas());
		result.include("proximasConsultas", consultaService.findNextConsultas());
		result.include("ultimosPacientes", pacienteService.findLastPacientes());
	}
	
	@Get("/resumo")
	public void resumo() {
		result.include("today", DateUtils.getDiaAtual());
		result.include("month", DateUtils.getMesAtual());
		result.include("year", DateUtils.getAnoAtual());
		
		result.include("qntConsultasHoje", consultaService.amountConsultasToday());
		result.include("qntConsultasSemana", consultaService.amountConsultasWeek());
		result.include("qntConsultasMes", consultaService.amountConsultasMonth());
		
		result.include("pcntConsultasParticularHoje", consultaService.amountPcntConsultasToday(TipoConsulta.PARTICULAR));
		result.include("pcntConsultasParticularSemana", consultaService.amountPcntConsultasWeek(TipoConsulta.PARTICULAR));
		result.include("pcntConsultasParticularMes", consultaService.amountPcntConsultasMonth(TipoConsulta.PARTICULAR));
		
		result.include("pcntConsultasConvenioHoje", consultaService.amountPcntConsultasToday(TipoConsulta.CONVENIO));
		result.include("pcntConsultasConvenioSemana", consultaService.amountPcntConsultasWeek(TipoConsulta.CONVENIO));
		result.include("pcntConsultasConvenioMes", consultaService.amountPcntConsultasMonth(TipoConsulta.CONVENIO));
		
		result.include("ultimasConsultas", consultaService.findLastConsultas());
		result.include("proximasConsultas", consultaService.findNextConsultas());
		result.include("ultimosPacientes", pacienteService.findLastPacientes());
	}
	
	@Get("/search/{val}")
	public void search(String val) {}
	
	@Get("/error")
	public void error() {}
	
}